package com.huqing.icu.dao;

import com.huqing.icu.dto.HouseDto;
import com.huqing.icu.enums.UserActionTypeEnum;
import com.huqing.icu.mapper.HouseUserActionRecordMapper;
import com.huqing.icu.model.HouseUserActionRecord;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * @Description 用户对房源的行为dao
 * @Author huqing
 * @Date 2025/9/13 18:59
 **/
@Repository
public class HouseUserActionRecordDao {

    @Resource
    private HouseUserActionRecordMapper houseUserActionRecordMapper;

    public Integer insertLikeRecord(Long userId, Long houseId, String houseTitle) {
        HouseUserActionRecord userActionRecord = new HouseUserActionRecord();
        userActionRecord.setUserId(userId);
        userActionRecord.setHouseId(houseId);
        userActionRecord.setHouseTitle(houseTitle);
        userActionRecord.setActionType(UserActionTypeEnum.LIKE.getCode());
        houseUserActionRecordMapper.insert(userActionRecord);
        return 1;
    }

    public Integer insertFavoriteRecord(Long userId, Long houseId, String houseTitle) {
        HouseUserActionRecord userActionRecord = new HouseUserActionRecord();
        userActionRecord.setUserId(userId);
        userActionRecord.setHouseId(houseId);
        userActionRecord.setHouseTitle(houseTitle);
        userActionRecord.setActionType(UserActionTypeEnum.FAVORITE.getCode());
        houseUserActionRecordMapper.insert(userActionRecord);
        return 1;
    }


    public List<HouseUserActionRecord> getList(Long userId, Integer busScene, Long houseId) {
        return houseUserActionRecordMapper.getList(userId, busScene, houseId);
    }

    public List<HouseUserActionRecord> selectByUserId(Long userId, List<Integer> houseIdList) {
        return houseUserActionRecordMapper.selectByUserId(userId, houseIdList);
    }

    public HouseUserActionRecord selectOneByUserId(Long userId, Long houseId, Integer actionType) {
        return houseUserActionRecordMapper.selectOneByUserId(userId, houseId, actionType);
    }

    public Integer deleteById(Long id) {
        return houseUserActionRecordMapper.deleteById(id);
    }

    public Integer getHouseNumByUserId(Long userId, Integer actionType) {
        return houseUserActionRecordMapper.getHouseNumByUserId(userId, actionType);
    }

    public List<HouseDto> selectHouseByUserId(Long userId, Integer actionType, Integer startIndex, Integer pageSize) {
        return houseUserActionRecordMapper.selectHouseByUserId(userId, actionType, startIndex, pageSize);
    }
}
